﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - StudentSecondDegree" 
*/ 

component 
	displayname="public.service.db.senate.sequence.StudentSecondDegree" 
	output=false 
	accessors=true 
	{

	property type="string" name="Grade" hint="年级";
	
	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getID() output=false {
		
		var nextID = getGrade() & "," & numberFormat(1, "0____");
		
		sql = "SELECT a.stusec_id 
				FROM t_student_secdegree a 
				WHERE a.grade = :grade  
				ORDER BY a.stusec_id DESC";
		
		queryObj = new Query( datasource=application.dnsMaster, maxRows=1 );
		queryObj.addParam( name="grade", value=getGrade(), cfsqltype="cf_sql_char" );
		var rs_check = queryObj.execute( sql=sql ).getResult();
		
		/* 
			主键生成规则 VARCHAR(12)
			
			年级 , 5位为流水号
		*/
		if (rs_check.recordCount) {
			/* 创建一个追加id */
			nextID = getGrade() & "," & numberFormat((right(rs_check["stusec_id"][1], 5) + 1), "0____");
			
		}

		return nextID;
		
	}

}

</cfscript>